<template>
    <div>
        <el-row>
            <el-col :span="24" class="main-h-center">
                <el-card style="width:400px;margin-top:50px;" shadow="never">
                    <el-form label-position="right" label-width="90px">
                        <el-form-item label="旧密码：" prop="pass">
                            <el-input type="password" autocomplete="off" v-model="oldpwd"></el-input>
                        </el-form-item>
                        <el-form-item label="新密码：" prop="checkPass">
                            <el-input type="password" autocomplete="off" v-model="newpwd"></el-input>
                        </el-form-item>
                        <el-form-item label="确认密码：" prop="age">
                            <el-input type="password" autocomplete="off" v-model="againpwd"></el-input>
                        </el-form-item>
                        <el-form-item style="margin-bottom: 0;">
                            <el-button type="primary" @click="resetpwd">立即修改</el-button>
                            <el-button @click="resetData">数据重置</el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                newpwd: "",
                oldpwd: "",
                againpwd: ""
            };
        },
        methods: {
            resetpwd() {
                if (this.$utils.isNullOrEmpty(this.newpwd)) {
                    this.$message.error("新密码不能为空！");
                    return;
                }
                if (this.newpwd.length < 5) {
                    this.$message.error("密码不能少于5位！");
                    return;
                }
                if (this.oldpwd === this.newpwd) {
                    this.$message.error("新密码不能和旧密码相同！");
                    return;
                }
                if (this.againpwd !== this.newpwd) {
                    this.$message.error("两次密码输入不一样！");
                    return;
                }
                this.$http
                    .post("/user/resetpwd", {
                        newpwd: this.newpwd,
                        oldpwd: this.oldpwd
                    })
                    .then(res => {
                        this.resetData();
                        if (res.code == 200) {
                            this.$message({
                                showClose: true,
                                message: res.msg,
                                type: "success"
                            });
                        } else {
                            this.$message.error(res.msg);
                        }
                    })
                    .catch(err => {
                        this.$message.error(err.msg);
                    });
            },
            resetData() {
                this.newpwd = "";
                this.oldpwd = "";
                this.againpwd = "";
            }
        }
    };
</script>
<style>
</style>

